package com.elead.oa.service.employee;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.elead.oa.common.PageObject;
import com.elead.oa.entity.Employee;
import com.elead.oa.mapper.EmployeeMapper;
import com.elead.oa.vo.EmployAttendanceVo;
import com.elead.oa.vo.EmployDepartmentVo;
import com.elead.oa.vo.LoginVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 考勤管理
 * EmployeeServiceImpl
 * 创建时间：2021年09月29日 10:06:21
 * @author xiaozuolin
 * @version 1.0.0
 */
@Service
@Slf4j
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    /**
     * 登陆实现
     *
     * @param loginVo
     * @return
     */
    @Override
    public Employee logined(LoginVo loginVo) {
        LambdaQueryWrapper<Employee> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Employee::getId, loginVo.getUsername());
        return this.getOne(lambdaQueryWrapper);
    }

    /**
     * 根据id联表查询员工考勤记录
     *
     * @param id
     * @return EmployAttendanceVo
     */
    @Override
    public List<EmployAttendanceVo> getAllAttendanceByEmployId(int id) {
        PageObject<EmployAttendanceVo> pageObject = new PageObject<>();
        return employeeMapper.getAllAttendanceByEmployId(id);
    }

    @Override
    public List<EmployDepartmentVo> employQuery() {
        return employeeMapper.employQuery();
    }

    @Override
    public EmployDepartmentVo getEmployDepartmentVoById(int id) {
        return employeeMapper.getEmployDepartmentVoById(id);
    }

    /**
     * 根据id查询信息
     *
     * @param id
     * @return 创建人:xiaozuolin
     * 创建时间：2021年09月29日 10:06:21
     * @version 1.0.0
     */
    @Override
    public Employee getEmployeeById(Integer id) {
        return this.getById(id);
    }

    /**
     * 保存&修改
     *
     * @param employee
     * @return 创建人:xiaozuolin
     * 创建时间：2021年09月29日 10:06:21
     * @version 1.0.0
     */
    @Override
    public Employee saveupdateEmployee(Employee employee) {
        boolean flag = this.saveOrUpdate(employee);
        return flag ? employee : null;
    }


    /**
     * 根据id删除
     *
     * @param id
     * @return 创建人:xiaozuolin
     * 创建时间：2021年09月29日 10:06:21
     * @version 1.0.0
     */
    @Override
    public int deleteEmployeeById(Integer id) {
        boolean b = this.removeById(id);
        return b ? 1 : 0;
    }
}